package com.realtyManage.springboot.Service.impl;

import com.realtyManage.springboot.Dao.BannerRepository;
import com.realtyManage.springboot.Model.Do.Banner;
import com.realtyManage.springboot.Service.IBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * IndexServiceImpl
 *
 * @Author 杭州素色网络科技有限公司
 * @Date 2019/3/22
 **/
@Service
@Transactional
public class BannerServiceImpl implements IBannerService{
    @Autowired
    private BannerRepository bannerRepository;

    @Override
    public boolean insert(Banner banner) {
        if(bannerRepository.saveAndFlush(banner)!=null){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public List<Banner> getIndexBanner(int state,String area) {
        List<Banner> result = null;
        if(area == null || area.toString()==""){
            result = bannerRepository.findByState(state);
        }else {
            result = bannerRepository.findByStateAndAreaLike(state,area);
        }
        return result;
    }

    @Override
    public Banner getOne(Integer id) {
        return bannerRepository.getOne(id);
    }
}
